//
//  IntroViewController.m
//  YYZB
//
//  Created by 顾悦 on 16/4/6.
//
//

#import "IntroViewController.h"

@interface IntroViewController ()

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;

@end

@implementation IntroViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.pagingEnabled = YES;
    self.scrollView.bounces = NO;
    
    NSUInteger pageCount = 3;
    CGRect screenBounds = [UIScreen mainScreen].bounds;
    CGFloat screenWidth = screenBounds.size.width;
    CGFloat screenHeight = screenBounds.size.height;
    self.scrollView.contentSize = CGSizeMake(screenWidth * pageCount, screenHeight);
    for (NSInteger i = 0; i < pageCount; i++) {
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"intro_0%@", @(i + 1)]]];
        imageView.frame = [UIScreen mainScreen].bounds;
        imageView.center = CGPointMake(CGRectGetMidX(screenBounds) + i * screenWidth, CGRectGetMidY(screenBounds));
        [self.scrollView addSubview:imageView];
        
        if (i == pageCount - 1) {
            imageView.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(start)];
            [imageView addGestureRecognizer:tap];
        }
    }
}

- (void)start {
    [UIView animateWithDuration:0.3
                     animations:^{
                         self.view.alpha = 0;
                     }
                     completion:^(BOOL finished) {
                         [self.view removeFromSuperview];
                         [self removeFromParentViewController];
                     }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
